package com.ztf.shopping.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ztf.shopping.bean.Article;
import com.ztf.shopping.dao.imp.ArticleDaoImp;
import com.ztf.shopping.service.ArticleService;
import com.ztf.shopping.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAllArticleServlet")
public class FindAllArticleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        ArticleService as = new ArticleDaoImp();
        List<Article> all = as.findAll();
        ObjectMapper om = new ObjectMapper();
        om.writeValue(response.getOutputStream(),all);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
